<?php

/*
Plugin Name: youxisoso search plugin
Plugin URI: http://www.youxisoso.com/
Description: 插件用来定制游戏搜搜网站的搜索控件和结果展示控件
Author: shiwei
Version: 1.0
Author URI: http://www.youxisoso.com/
*/







function samePageDisplay(){
?>
	<div>
	<script type="text/javascript">
	function getcode1(){
		var textVal = "" ;
		var searchinputdiv = document.getElementById('searchinputdiv1').value ;
		if(searchinputdiv==null || searchinputdiv==""){
			alert("请填写搜索组件ID!");
			return ;
		}
		
		var searchresultdiv = document.getElementById('searchresultdiv1').value ;
		if(searchresultdiv==null || searchresultdiv==""){
			alert("请填写搜索结果ID!");
			return ;
		}
		if(searchinputdiv==searchresultdiv){
			alert("搜索组件ID和搜索结果ID不能相同!");
			return ;
		}
		var textVal = "<div id='"+searchinputdiv+"'></div><div  id='"+searchresultdiv+"' ></div>"+
			"<script type='text/javascript' src='http://www.youxisoso.com/wp-content/themes/youxisoso/searchcomponent/searchinput.js' >"+
			"<\/script> <script type='text/javascript' >"+
			"initSearchInput('"+searchinputdiv+"','"+searchresultdiv+"') ;"+
			"<\/script>";
		document.getElementById('reulstcode1').value =textVal ;
		
	}
	</script>
		<div>
			<label for="searchinputdiv1" >搜索组件ID:</label>
			<input type="text" id="searchinputdiv1" name="searchinputdiv">
		</div>
		
		<div>
			<label for="searchresultdiv1" >搜索结果ID:</label>
			<input type="text" id="searchresultdiv1" name="searchresultdiv">
		</div>
		<div>
			<label for="reulstcode1" >代码:</label>
			<textarea id="reulstcode1" rows="5" cols="100" readonly="readonly"></textarea>
		</div>
		<input type="button" onclick="getcode1();" value="获取代码">
	</div>
<?php
	
}

function diffPageDisplay(){
?>
	<div>
		<script type="text/javascript">
	function getcode2(){
		var textVal = "" ;
		var searchinputdiv = document.getElementById('searchinputdiv2').value ;
		if(searchinputdiv==null || searchinputdiv==""){
			alert("请填写搜索组件ID!");
			return ;
		}
		
		var searchresultdiv = document.getElementById('searchresultdiv2').value ;
		if(searchresultdiv==null || searchresultdiv==""){
			alert("请填写搜索结果ID!");
			return ;
		}
		
		var searchresulturl = document.getElementById('searchresulturl2').value ;
		if(searchresulturl==null || searchresulturl==""){
			alert("URL不能为空!");
			return ;
		}
		
		var textInputVal = "<div id='"+searchinputdiv+"'><\/div>"+
			"<script type='text/javascript' src='http://www.youxisoso.com/wp-content/themes/youxisoso/searchcomponent/searchinput.js' ><\/script>"+
			"<script type='text/javascript' >initSearchInput('"+searchinputdiv+"','"+searchresultdiv+"','"+searchresulturl+"') ;<\/script>";

		var textResultVal ="<\?php "+
			"$resultCat = $_GET['cat']; "+ 
			"if(empty($resultCat)){ "	 +
			"	$resultCat = $_POST['cat'] ;"+
			"}"+
			"$resultDIV = $_GET['div'];"+  
			"if(empty($resultCat)){"+ 	 
			"	$resultDIV = $_POST['div'] ;"+
			"}" +
			"$s = $_GET['keyword']; "+ 
			"if(empty($resultCat)){ "+	 
			"	$s = $_POST['keyword'] ;"+
			"} "+
			"\?>"+
			"<script type='text/javascript' src='http://www.youxisoso.com/wp-content/themes/youxisoso/searchcomponent/searchinput.js' ><\/script>"+ 
			"<div id='<\?php echo $resultDIV; \?>'></div>"+
			"<script type='text/javascript' >"+
			"getResult('<\?php echo $s;?>','<\?php echo $resultCat ;?>',0,'<\?php echo $resultDIV;?>'); "+
			"<\/script>";
		
		document.getElementById('searchinputcode2').value =textInputVal ;
		document.getElementById('reulstcode2').value =textResultVal ;
		
	}
	</script>
		<div>
			<label for="searchinputdiv2" >搜索组件ID:</label>
			<input type="text" id="searchinputdiv2" name="searchinputdiv">
		</div>
		
		<div>
			<label for="searchinputcode2" >搜索组件代码:</label>
			<textarea id="searchinputcode2" rows="5" cols="100" readonly="readonly"></textarea>
		</div>
		
		
		<div>
			<label for="searchresultdiv2" >搜索结果ID:</label>
			<input type="text" id="searchresultdiv2" name="searchresultdiv">
		</div>
		
		<div>
			<label for="searchresulturl2" >结果URL:</label>
			<input type="text" id="searchresulturl2" name="searchresulturl">
		</div>
		<div>
			<label for="reulstcode2" >搜索结果组件代码:</label>
			<textarea id="reulstcode2" rows="5" cols="100" readonly="readonly"></textarea>
		</div>
		
		
		<input type="button" onclick="getcode2();" value="获取代码">
		
	</div>
<?php
	
}
function onlyDisplayData(){
$paramer= array(
	"6"=>"Flash游戏",
	"7"=>"网页游戏",
	"8"=>"手机游戏"
);
?>
	<div>
	<script type="text/javascript">
	function getcode3(){
		var textVal = "" ;
		var keywords = document.getElementById('keywords3').value ;
		if(keywords==null || keywords==""){
			alert("请填写搜索关键词!");
			return ;
		}
		var cats = document.getElementById('cats3') ;
		var catname = cats.options[cats.selectedIndex].value ;
		var divid = document.getElementById('divid3').value ;
		if(divid==null || divid==""){
			alert("请填写结果组件ID!");
			return ;
		}
		var textVal = "<script type='text/javascript' src='http://www.youxisoso.com/wp-content/themes/youxisoso/searchcomponent/searchinput.js' >"+
			"<\/script> <div id='"+divid+"' >" +
			"<script type='text/javascript' >" +
			" 	 getResult('"+keywords+"','"+catname+"',0,'"+divid+"' );<\/script > <\/div >";
		document.getElementById('reulstcode3').value =textVal ;
		
	}
	</script>
		<div>
			<label for="keywords3" >搜索关键词:</label>
			<input type="text" id="keywords3" name="keywords">
		</div>
		<div>
			<label for="divid3" >结果组件ID:</label>
			<input type="text" id="divid3" name="divid">
		</div>
		<div>
			<label for="cats3" >游戏类型:</label>
			<select id="cats3" >
				<option value="">全部游戏</option>
<?php 
				foreach($paramer as $v){
?>
					<option value="<?php echo $v; ?>"><?php echo $v; ?></option>
<?php 				
				}
?>
			</select>
		</div>	
		<div>
			<label for="reulstcode3" >请复制代码:</label>
			<textarea rows="5" cols="100" id="reulstcode3" readonly="readonly"></textarea>
		</div>
		
		<input type="button" onclick="getcode3();" value="获取代码">
	</div>
<?php
}

function search_desc(){
?>
	<script type="text/javascript">
	function hiddenDiv(divid){
		if(divid==1){
			document.getElementById("samePageDisplay").style.display="block";
			document.getElementById("diffPageDisplay").style.display="none";
			document.getElementById("onlyDisplayData").style.display="none";
			
		}else if(divid==2){
			document.getElementById("samePageDisplay").style.display="none";
			document.getElementById("diffPageDisplay").style.display="block";
			document.getElementById("onlyDisplayData").style.display="none";
			
			
		}else if(divid==3){
			document.getElementById("samePageDisplay").style.display="none";
			document.getElementById("diffPageDisplay").style.display="none";
			document.getElementById("onlyDisplayData").style.display="block";
		}
	}
	</script>
	<div><input type="radio" name="sele" value="1" onclick="hiddenDiv(1);"/>1- 在同页面显示搜索结果</div>
	<div id='samePageDisplay'>
<?php 	
	samePageDisplay();
?>
	
	</div>
	<div><input type="radio" name="sele" value="2" onclick="hiddenDiv(2);"/>2- 在不同页面显示搜索结果</div>
	<div id='diffPageDisplay' style="display:none;">
<?php 
	diffPageDisplay();
?>
	</div>
	<div><input type="radio" name="sele" value="3" onclick="hiddenDiv(3);"/>3- 自定义关键字</div>
	<div id='onlyDisplayData' style="display:none;">
<?php 
	onlyDisplayData();
?>
	</div>
	
<?php 
}

add_action('admin_menu','add_search_plugin',1);

function add_search_plugin(){
	add_menu_page('游戏搜搜搜索插件', '游戏搜搜插件代码生成', 8, __FILE__, 'search_desc');
	 
	//add_submenu_page(__FILE__, '同页面显示', '同页面显示', 8, 'sub-page3', 'samePageDisplay');
	 
   // add_submenu_page(__FILE__, '不同页面显示', '不同页面显示', 8, 'sub-page4', 'diffPageDisplay');

   // add_submenu_page(__FILE__, '只显示结果', '只显示结果', 8, 'sub-page5', 'onlyDisplayData');
}
?>